package org.example.rubbish.mapper;

import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.example.rubbish.entity.Alarm;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface AlarmMapper {

    int insert(Alarm alarm);

    int updateAcknowledgedStatus(Alarm alarm);

    List<Alarm> selectByAcknowledgedStatus(@Param("acknowledged") Boolean acknowledged);

    List<Alarm> selectBySourceAndTime(@Param("source") String source,
                                      @Param("startTime") LocalDateTime startTime);

    int countUnacknowledgedAlarms();

    List<Alarm> selectComplexQuery(Map<String, Object> params);

    Alarm selectById(@Param("id") Long id);

    Alarm selectByAlarmId(@Param("alarmId") String alarmId);

    int batchUpdateAcknowledgedStatus(@Param("alarmIds") List<String> alarmIds,
                                      @Param("acknowledged") Boolean acknowledged,
                                      @Param("acknowledgedBy") String acknowledgedBy,
                                      @Param("acknowledgedTime") LocalDateTime acknowledgedTime,
                                      @Param("updateTime") LocalDateTime updateTime);

    int deleteById(@Param("id") Long id);


    @MapKey("statKey")
    Map<String, Object> countByTimeRange(@Param("startTime") LocalDateTime startTime,
                                         @Param("endTime") LocalDateTime endTime);

}